package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
///admin/product/saveSkuInfo
public class SkuManageController {
    @Autowired
    private ManageService manageService;
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        manageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }
    @GetMapping("/list/{page}/{limit}")///admin/product/list/{page}/{limit}
    public Result getSkuInfoPage( @PathVariable Long page,
                                  @PathVariable Long limit){
        Page<SkuInfo> skuInfoPage = new Page<>(page, limit);
        IPage iPage =manageService.getSkuInfoPage(skuInfoPage);
        return Result.ok(iPage);
    }
    @GetMapping("/onSale/{skuId}")///admin/product/onSale/{skuId}
    public Result onSale(@PathVariable Long skuId){
          manageService.onSale(skuId);
          return Result.ok();
    }
    @GetMapping("/cancelSale/{skuId}")///admin/product/cancelSale/{skuId}
    public Result cancelSale (@PathVariable Long skuId){
          manageService.cancelSale(skuId);
          return Result.ok();
    }
}
